<?php
/**
 * Created by PhpStorm.
 * User: liyu
 * Date: 2018/4/27
 * Time: 下午4:39
 */

namespace app\api\service;


class LogService extends Base
{
    public function getLogInfoListByMap($where,$page)
    {
        $start_time = $where['start_time'];
        $end_time = $where['end_time'];
        $map = "create_time between '$start_time' and '$end_time'";
        $list = [];
        $count1 = db()->query("select count(*) as `num` from t_create_log WHERE $map");
        $count2 = db()->query("select count(*) as `num` from t_update_log WHERE $map");
        $count = $count1[0]['num'] + $count2[0]['num'];
        $list_max_rows = config('list_rows_20');
        $current_page = (int)$page;
        $start_position = ($current_page - 1) * $list_max_rows;
        $total_page = ceil($count/$list_max_rows);
        if ($count > 0) {
            $sql = "select * from (select `guid`,`controller`,`action`,`create_time`,`save_data` from t_create_log WHERE $map UNION ALL SELECT `guid`,`controller`,`action`,`create_time`,`save_data` FROM t_update_log WHERE $map) as t ORDER BY create_time DESC LIMIT $start_position,$list_max_rows";
            $list = db()->query($sql);
        }
        $result = [
            'count' => $count,
            'list_max_rows' => $list_max_rows,
            'list_rows' => count($list),
            'total_page' => $total_page,
            'current_page' => $current_page,
            'list' => $list
        ];
        return $result;
    }
}